package com.ayuku;

import java.util.Locale;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.wb.swt.SWTResourceManager;

import com.ayuku.commons.AYConst;
import com.ayuku.commons.AyukuDB;
import com.ayuku.commons.Util;
import com.ayuku.retail.persistence.model.AppUsers;

public class MainApp extends org.eclipse.swt.widgets.Dialog {
	public MainApp(Shell arg0) {
		super(arg0);
	}

	public static void main(String[] args) throws Exception {
		AyukuDB.openDB();
		Locale.setDefault(Locale.US);
		new LoginForm();

		if (Util.getCurrentUser() == null) {
			System.exit(0);
		}

		Display display = Display.getDefault();
		Shell shell = new Shell(display);
		new MainWindow(shell, SWT.NULL);

		shell.setLayout(new FillLayout());
		shell.setImage(SWTResourceManager.getImage(MainApp.class, "/images/app/group.png"));
		AppUsers usr = Util.getCurrentUser();

		shell.setText(AYConst.APP_TITLE + "   |  user: " + usr.getName()
				+ "  |  group: " + usr.getGroupId());

		shell.layout();

		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

}
